package leetcode.D100.T48;

/**
 * @File Info: leetcode -- <Solution>
 * @Author: DYZ
 * @Create: 2021-08-11 21:25:11 星期三
 */

public class Solution {
    // 一刷
    /*public void rotate(int[][] matrix) {
        int n = matrix.length;
        for(int s=0; s<(n/2); ++s) {
            for(int k=0; k<(n-2*s-1); ++k) {
                int temp = matrix[s][s+k];
                matrix[s][s+k] = matrix[n-1-s-k][s];
                matrix[n-1-s-k][s] = matrix[n-1-s][n-1-s-k];
                matrix[n-1-s][n-1-s-k] = matrix[s+k][n-1-s];
                matrix[s+k][n-1-s] = temp;
            }
        }
    }*/

    // 二刷
    public void rotate(int[][] matrix) {
        int n = matrix.length;
        for (int i=0; i<n/2; ++i) {
            for (int j=i; j<n-1-i; ++j) {
                int t = matrix[i][j];
                matrix[i][j] = matrix[n-1-j][i];
                matrix[n-1-j][i] = matrix[n-1-i][n-1-j];
                matrix[n-1-i][n-1-j] = matrix[j][n-1-i];
                matrix[j][n-1-i] = t;
            }
        }
    }
}
